<template>
  <div class="app-container">
    <h3 style="font-weight: bold;">查询条件</h3>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-row>
        <el-col span="20" offset="1">
          <el-form-item label="职工编号" prop="F0601">
            <el-input
              v-model="queryParams.F0601"
              placeholder="请输入职工编号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="姓名" prop="F0602">
            <el-input
              v-model="queryParams.F0602"
              placeholder="请输入姓名"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="电话" prop="F0604">
            <el-input
              v-model="queryParams.F0604"
              placeholder="请输入电话"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        
        <el-col span="3" >
          <el-form-item id="query-button">
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col span="20" offset="1">
          <el-form-item label="状态" prop="F0610">
            <el-select v-model="queryParams.F0610" placeholder="请选择状态" clearable>
              <el-option
                v-for="dict in dict.type.sys_common_status"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="身份" prop="F0609">
            <el-select v-model="queryParams.F0609" placeholder="请选择身份" clearable>
              <el-option
                v-for="(identify,index) in identifyList"
                :key="index"
                :value="identify"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="部门" prop="F0501">
            <el-select v-model="queryParams.F0501" placeholder="请选择部门" clearable>
              <el-option
                v-for="(department,index) in departemntList"
                :key="index"
                :value="department.f0501"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <el-row :gutter="10" class="mb8">

      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['authcenter:T06:edit']"
        >设置</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['authcenter:T06:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['authcenter:T06:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="T06List" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="职工编号" align="center" prop="F0601" />
      <el-table-column label="部门" align="center" prop="F0501" />
      <el-table-column label="姓名" align="center" prop="F0602" />
      <el-table-column label="电话" align="center" prop="F0604" />
      <el-table-column label="身份" align="center" prop="F0609" />
      <el-table-column label="余额" align="center" prop="F0611"/>
      <el-table-column label="状态" align="center" prop="F0610">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_common_status" :value="scope.row.F0610"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['authcenter:T06:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['authcenter:T06:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改授权中心对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<style scoped>
  #query-button{
    min-width: 160px;
  }
</style>

<script>
import { listT06, getT06, delT06, addT06, updateT06 } from "@/api/authcenter/T06";
import { getDepartmentList, getIdentifyList } from "../../../api/authcenter/T06";

export default {
  name: "T06",
  dicts: ['sys_common_status', 'client_user_resettime'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 授权中心表格数据
      T06List: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        F0601: null,
        F0501: null,
        F0602: null,
        F0604: null,
        F0609: null,
        F0610: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      identifyList:[],
      departemntList:[],
    };
  },
  created() {
    this.getList();
    this.identifySelectInit();
    this.departmentSelectInit();
  },
  mounted(){

  },
  methods: {
    /** 查询授权中心列表 */
    getList() {
      this.loading = true;
      listT06(this.queryParams).then(response => {
        this.T06List = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    identifySelectInit(){
      getIdentifyList().then(rep=>{
        this.identifyList = rep.data;
      })
    },
      departmentSelectInit(){
        getDepartmentList().then(rep=>{
          this.departemntList = rep.rows;
        })
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        F0601: null,
        F0501: null,
        F0602: null,
        F0603: null,
        F0604: null,
        F0605: null,
        F0606: null,
        F0607: null,
        F0608: null,
        F0609: null,
        F0610: null,
        F0611: null,
        F0612: null,
        F0613: null,
        F0614: null,
        F0615: null,
        F0616: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.F0601)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加授权中心";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const F0601 = row.F0601 || this.ids
      getT06(F0601).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改授权中心";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.F0601 != null) {
            updateT06(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addT06(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const F0601s = row.F0601 || this.ids;
      this.$modal.confirm('是否确认删除授权中心编号为"' + F0601s + '"的数据项？').then(function() {
        return delT06(F0601s);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('authcenter/T06/export', {
        ...this.queryParams
      }, `T06_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
